package net.lab1024.sa.admin.module.sast.tool.service;

import jakarta.annotation.Resource;
import net.lab1024.sa.admin.module.sast.task.dao.TaskDao;
import net.lab1024.sa.admin.module.sast.tool.dao.ToolConfigDao;
import net.lab1024.sa.admin.module.sast.tool.domain.ToolConfigEntity;
import net.lab1024.sa.admin.module.sast.tool.domain.ToolConfigForm;
import net.lab1024.sa.base.common.util.SmartBeanUtil;
import org.springframework.stereotype.Service;

import java.util.UUID;

@Service
public class ToolConfigService {

    @Resource
    private ToolConfigDao toolConfigDao;

    @Resource
    private TaskDao taskDao;

    public ToolConfigEntity getByTaskUuid(String taskUuid) {
        String uuid=taskDao.getToolUuidByTaskUuid(taskUuid);
        return toolConfigDao.getByUuid(uuid);
    }

    /**
     *
     * @param form
     * @return uuid t_tools_codeql的uuid,可填回t_task表进行关联
     *
     * 为了可以直接获取插入数据的uuid，选择不在数据库生成而是在应用层生成UUID
     */
    public String create(ToolConfigForm form){
        ToolConfigEntity toolConfig=SmartBeanUtil.copy(form, ToolConfigEntity.class);
        String uuid= UUID.randomUUID().toString();
        toolConfig.setUuid(uuid);
        toolConfigDao.create(toolConfig);
        return uuid;
    }

    public void update(ToolConfigForm form){
        ToolConfigEntity toolConfig=SmartBeanUtil.copy(form, ToolConfigEntity.class);
        toolConfigDao.update(toolConfig);
    }

    public ToolConfigEntity getByUuid(String uuid) {
        return toolConfigDao.getByUuid(uuid);
    }
}
